package cn.onlineclass.service;

import cn.onlineclass.dao.ORatationMapper;
import cn.onlineclass.entity.ORatation;
import cn.onlineclass.util.AjaxPage;
import cn.onlineclass.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class ORatationService {
    public static final ORatationService INST=new ORatationService();
    public AjaxPage search(int pageNo, int pageSize, boolean inuse) {
        SqlSession s = MybatisUtil.get();
        try {
            ORatationMapper mapper = s.getMapper(ORatationMapper.class);

            List<ORatation> search = mapper.search(pageNo, pageSize,inuse);
            int total = mapper.searchTotal(inuse);
            return new AjaxPage(search,total,pageNo,pageSize);
        } finally {
            MybatisUtil.closeSession(s);
        }
    }
    public int add(ORatation ORatation){
        SqlSession session = MybatisUtil.get();
        try {
            ORatationMapper mapper = session.getMapper(ORatationMapper.class);
            return mapper.add(ORatation);
        }finally {
            MybatisUtil.closeSession(session);
        }
    }

    public ORatation get(long id){
        SqlSession session = MybatisUtil.get();
        try {
            ORatationMapper mapper = session.getMapper(ORatationMapper.class);
            return mapper.get(id);
        }finally {
            MybatisUtil.closeSession(session);
        }
    }

    public int update(ORatation ORatation){
        SqlSession session = MybatisUtil.get();
        try {
            ORatationMapper mapper = session.getMapper(ORatationMapper.class);
            return mapper.update(ORatation);
        }finally {
            MybatisUtil.closeSession(session);
        }
    }

    public int del(ORatation ORatation){
        SqlSession session = MybatisUtil.get();
        try {
            ORatationMapper mapper = session.getMapper(ORatationMapper.class);
            return mapper.update(ORatation);
        }finally {
            MybatisUtil.closeSession(session);
        }
    }
}
